﻿// Config_General_Dlg.cpp: 实现文件
//

#include "stdafx.h"
#include "Clicker.h"
#include "Config_General_Dlg.h"
#include "afxdialogex.h"
#include "DefInfo/GameInfo.h"


// Config_General_Dlg 对话框

IMPLEMENT_DYNAMIC(Config_General_Dlg, CDialogEx)


static Config_General_Dlg* inst = NULL;

Config_General_Dlg::Config_General_Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONFIG_GENERAL, pParent)
{
	inst = this;
}

Config_General_Dlg::~Config_General_Dlg()
{
	inst = NULL;
}

void Config_General_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_MIN_HEAL_LOWER, edt_min_heal_lower_);
	DDX_Control(pDX, IDC_SLIDER_MIN_HEAL_LOWER, slider_min_heal_lower_);
	DDX_Control(pDX, IDC_CHECK_FORCE_ATTACK_TARGET, btn_force_attack_enable_);
	DDX_Control(pDX, IDC_SLIDER_AOE_NUMBER, slider_aoe_num_);
	DDX_Control(pDX, IDC_STATIC_AOE_NUMBER, text_aoe_num_);
	DDX_Control(pDX, IDC_CHECK_FORCE_AOE_TARGET, btn_force_aoe_target_);
	DDX_Control(pDX, IDC_CHECK_USE_AZERITE_SPELL, btn_use_azerite_neck_spell);
	DDX_Control(pDX, IDC_CHECK_USE_ConRo_Spell, btn_use_conro_spell);
}


BEGIN_MESSAGE_MAP(Config_General_Dlg, CDialogEx)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_CHECK_FORCE_ATTACK_TARGET, &Config_General_Dlg::OnClickedCheckForceAttackTarget)
	ON_BN_CLICKED(IDC_CHECK_FORCE_AOE_TARGET, &Config_General_Dlg::OnClickedCheckForceAoeTarget)
	ON_BN_CLICKED(IDC_CHECK_USE_AZERITE_SPELL, &Config_General_Dlg::OnClickedCheckUseAzeriteSpell)
	ON_BN_CLICKED(IDC_CHECK_USE_ConRo_Spell, &Config_General_Dlg::OnBnClickedCheckUseConroSpell)
END_MESSAGE_MAP()


// Config_General_Dlg 消息处理程序


BOOL Config_General_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化

	slider_min_heal_lower_.SetRange(0, 1000);
	slider_min_heal_lower_.SetLineSize(1);
	slider_min_heal_lower_.SetPos(GameInfo::inst().GetRoutineConfig().general_config.heal_min_lower);
	slider_aoe_num_.SetRange(0, 20);
	slider_aoe_num_.SetLineSize(1);
	slider_aoe_num_.SetPos(GameInfo::inst().GetRoutineConfig().general_config.force_aoe_number);
	btn_force_attack_enable_.SetCheck(GameInfo::inst().GetRoutineConfig().general_config.force_attack_target);
	UpdateSlider_1_Text(GameInfo::inst().GetRoutineConfig().general_config.heal_min_lower);
	UpdateSlider_AOE_Number_Text(GameInfo::inst().GetRoutineConfig().general_config.force_aoe_number);
	btn_use_azerite_neck_spell.SetCheck(GameInfo::inst().GetRoutineConfig().general_config.use_azerite_neck_spell);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void Config_General_Dlg::UpdateSlider_1_Text(int pos)
{
	CString str;
	str.Format(L"%.3f%%", (pos / 1000.0f)*100.0f);
	edt_min_heal_lower_.SetWindowText(str);
}

void Config_General_Dlg::UpdateSlider_AOE_Number_Text(int pos)
{
	CString str;
	str.Format(L"个数:%d", pos);
	text_aoe_num_.SetWindowText(str);
}

void Config_General_Dlg::SetCheck(int check_index, bool check)
{
	if (check_index == 2)
	{
		GameInfo::inst().GetRoutineConfig().general_config.force_aoe_target = check;
		btn_force_attack_enable_.SetCheck((int)GameInfo::inst().GetRoutineConfig().general_config.force_attack_target);
	}
}


Config_General_Dlg* Config_General_Dlg::Inst()
{
	return inst;
}

void Config_General_Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CSliderCtrl* slider = (CSliderCtrl*)pScrollBar;
	if (slider == &slider_min_heal_lower_)
	{
		int pos = slider->GetPos();
		UpdateSlider_1_Text(pos);
		GameInfo::inst().GetRoutineConfig().general_config.heal_min_lower = pos;
	}
	if (slider == &slider_aoe_num_)
	{
		int pos = slider->GetPos();
		UpdateSlider_AOE_Number_Text(pos);
		GameInfo::inst().GetRoutineConfig().general_config.force_aoe_number = pos;
	}
	CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}


void Config_General_Dlg::OnClickedCheckForceAttackTarget()
{
	// TODO: 在此添加控件通知处理程序代码

	GameInfo::inst().GetRoutineConfig().general_config.force_attack_target = (bool)btn_force_attack_enable_.GetCheck();
}


void Config_General_Dlg::OnClickedCheckForceAoeTarget()
{
	GameInfo::inst().GetRoutineConfig().general_config.force_aoe_target = (bool)btn_force_aoe_target_.GetCheck();
}




void Config_General_Dlg::OnClickedCheckUseAzeriteSpell()
{
	GameInfo::inst().GetRoutineConfig().general_config.use_azerite_neck_spell = (bool)btn_use_azerite_neck_spell.GetCheck();
}


void Config_General_Dlg::OnBnClickedCheckUseConroSpell()
{
	GameInfo::inst().GetRoutineConfig().general_config.use_conro_spell = (bool)btn_use_conro_spell.GetCheck();
}
